/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * plantilla.java
 *
 * Created on 31/10/2011, 12:00:51 AM
 */
package vista.panel.altas;

import controlador.ControlEventos;
import modelo.Producto;
import modelo.Productor;

/**
 *
 * @author Elias Mendoza
 */
public class AltaProducto extends javax.swing.JPanel {
  ControlEventos ce;
  int index=0;

  /** Creates new form plantilla */
  public AltaProducto() {
    initComponents();
    ce = new ControlEventos();
    ce.llenaComponenteProductor(productores);    
  }

  /** This method is called from within the constructor to
   * initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is
   * always regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panel2 = new javax.swing.JPanel();
        jSplitPane1 = new javax.swing.JSplitPane();
        jLabel1 = new javax.swing.JLabel();
        nombre = new javax.swing.JTextField();
        jSplitPane2 = new javax.swing.JSplitPane();
        jLabel2 = new javax.swing.JLabel();
        tipo = new javax.swing.JTextField();
        jSplitPane3 = new javax.swing.JSplitPane();
        jLabel3 = new javax.swing.JLabel();
        productores = new javax.swing.JComboBox();
        jPanel1 = new javax.swing.JPanel();
        jSplitPane6 = new javax.swing.JSplitPane();
        borrar = new javax.swing.JButton();
        registrar = new javax.swing.JButton();

        setBackground(new java.awt.Color(255, 255, 255));
        setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Registrar Producto", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Maiandra GD", 1, 14))); // NOI18N

        panel2.setBackground(new java.awt.Color(255, 255, 255));
        panel2.setAutoscrolls(true);
        panel2.setLayout(new java.awt.GridLayout(4, 0, 0, 5));

        jSplitPane1.setBackground(new java.awt.Color(255, 255, 255));
        jSplitPane1.setBorder(null);
        jSplitPane1.setDividerSize(3);
        jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);

        jLabel1.setBackground(new java.awt.Color(255, 255, 255));
        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(0, 153, 102));
        jLabel1.setText("Nombre:");
        jSplitPane1.setLeftComponent(jLabel1);

        nombre.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        jSplitPane1.setRightComponent(nombre);

        panel2.add(jSplitPane1);

        jSplitPane2.setBackground(new java.awt.Color(255, 255, 255));
        jSplitPane2.setBorder(null);
        jSplitPane2.setDividerSize(3);
        jSplitPane2.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);

        jLabel2.setBackground(new java.awt.Color(255, 255, 255));
        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(0, 153, 102));
        jLabel2.setText("Tipo:");
        jSplitPane2.setLeftComponent(jLabel2);

        tipo.setFont(new java.awt.Font("Times New Roman", 1, 12));
        jSplitPane2.setRightComponent(tipo);

        panel2.add(jSplitPane2);

        jSplitPane3.setBackground(new java.awt.Color(255, 255, 255));
        jSplitPane3.setBorder(null);
        jSplitPane3.setDividerSize(3);
        jSplitPane3.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);

        jLabel3.setBackground(new java.awt.Color(255, 255, 255));
        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel3.setForeground(new java.awt.Color(0, 153, 102));
        jLabel3.setText("Productor:");
        jSplitPane3.setLeftComponent(jLabel3);

        productores.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                productoresActionPerformed(evt);
            }
        });
        jSplitPane3.setRightComponent(productores);

        panel2.add(jSplitPane3);

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setLayout(new java.awt.GridBagLayout());

        borrar.setFont(new java.awt.Font("Maiandra GD", 1, 14)); // NOI18N
        borrar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vista/img/borrar.png"))); // NOI18N
        borrar.setBorder(null);
        borrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                borrarActionPerformed(evt);
            }
        });
        jSplitPane6.setRightComponent(borrar);

        registrar.setFont(new java.awt.Font("Maiandra GD", 1, 14)); // NOI18N
        registrar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vista/img/registrar.png"))); // NOI18N
        registrar.setBorder(null);
        registrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                registrarActionPerformed(evt);
            }
        });
        jSplitPane6.setLeftComponent(registrar);

        jPanel1.add(jSplitPane6, new java.awt.GridBagConstraints());

        panel2.add(jPanel1);

        add(panel2);
    }// </editor-fold>//GEN-END:initComponents

  private void registrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_registrarActionPerformed
    // TODO add your handling code here:
    Producto p = new Producto();
    p.setNombre(nombre.getText());
    p.setTipo(tipo.getText());
    Productor ptor = (Productor) productores.getSelectedItem();
    p.setProductor(ptor);
 
    ce.inserta(p);
  }//GEN-LAST:event_registrarActionPerformed

  private void borrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_borrarActionPerformed
    // TODO add your handling code here:
    
  }//GEN-LAST:event_borrarActionPerformed

  private void productoresActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_productoresActionPerformed
    // TODO add your handling code here:
    
  }//GEN-LAST:event_productoresActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton borrar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JSplitPane jSplitPane2;
    private javax.swing.JSplitPane jSplitPane3;
    private javax.swing.JSplitPane jSplitPane6;
    private javax.swing.JTextField nombre;
    private javax.swing.JPanel panel2;
    private javax.swing.JComboBox productores;
    private javax.swing.JButton registrar;
    private javax.swing.JTextField tipo;
    // End of variables declaration//GEN-END:variables
}
